<?php
namespace Admin\Models\ims;

use Admin\Models\BaseModel;
use Helpers\Cache;

class XHImsProdType extends BaseModel
{

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=11, nullable=false)
     */
    public $iTypeId;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $sTypeName;

    /**
     *
     * @var integer
     * @Column(type="integer", length=4, nullable=true)
     */
    public $bDelete;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tCreateDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tLastModifyDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iLastModifyUserId;



    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSource("XHIms_ProdType");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHIms_ProdType';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XHImsProdType[]|XHImsProdType|\Phalcon\Mvc\Model\ResultSetInterface
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XHImsProdType|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public static function getProdTypeEnum(){
        if(!Cache::exists('prodTypeEnum')){
            $types=self::find([
                'columns'   => 'iTypeId,sTypeName',
                'conditions' => 'bDelete=0',
            ])->toArray();
            $array=array_column($types,'sTypeName','iTypeId');
            Cache::save('prodTypeEnum',$array);
            return $array;
        }else{
            return Cache::get('prodTypeEnum');
        }

    }

}
